package com.wangxiaonan.process.Controller;

import com.wangxiaonan.process.service.ProcessService;
import freemarker.template.TemplateException;
import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: wangxiaonan
 * @Date: 2019/2/27
 **/
@RestController
@RequestMapping("/download")
public class DownLoadController {

    @Resource
    private ProcessService processService;

    @RequestMapping(value = "/{file_name}", produces = {MediaType.TEXT_XML_VALUE})
    public String xmlDownload(@PathVariable(name = "file_name") String fileName, HttpServletRequest request,
            HttpServletResponse response) throws IOException, TemplateException {
//        try (PrintWriter printWriter = response.getWriter()){
//            printWriter.write(processService.outputTemplate(fileName));
//            printWriter.flush();
//        } catch (IOException e) {
//            e.printStackTrace();
//        } catch (TemplateException e) {
//            e.printStackTrace();
//        }
        return processService.outputTemplate(fileName);
    }

}
